<template>
	<div class="infobar">
		<el-row>
			<el-col>
				<label><i class="el-icon-caret-right"></i>分诊护士:</label>
				<el-input class="triage" v-model="patient.nurse" style="width:160px;"></el-input>

				<label><i class="el-icon-caret-right"></i>诊治医生:</label>
				<el-autocomplete class="triage userSearch" 
				v-model="patient.doctor"
				:fetch-suggestions="queryDoctors"
				@select="confirmDoctor"
				style="width:160px;"></el-autocomplete>

			</el-col>
		</el-row>
	</div>
</template>
<script type="text/javascript">
	export default{
		name:"InfoBar",
		data(){
			return {
				curUser:{},
			}
		},
		computed:{
			patient:{
				set(value){
				},
				get(){
					return this.$store.state.patient;
				}
			}
		},
		methods:{
			queryDoctors:function(keyWords,cb){
				var vm =this;
				if (!keyWords) {
					keyWords="2018";
				}
				this.$axios.queryDoctors(keyWords,vm.curUser.hospitalCode).then(function(res){
					var doctors = [];
					if (res.data&&res.data.data) {
						doctors = res.data.data;
					}
					doctors.forEach(function(doctor){
						doctor.value = doctor.userNickName;
					});
					cb(doctors);
				},function(res){
					console.log("请求医生信息错误");
				});
			},
			confirmDoctor:function(item){
				this.patient.doctor = item.userNickName;
			}
		},
		mounted(){
			  var vm = this;
			  vm.curUser = this.$cookies.get("curUser");
			  if ("分诊台"==vm.curUser.userBelong) {
			  	vm.$set(vm.patient,"nurse",vm.curUser.userNickName+vm.curUser.userName);
			  }else if (!vm.patient.doctor){
			  	vm.$set(vm.patient,"doctor",vm.curUser.userNickName+vm.curUser.userName);
			  }
		},
	}
</script>
<style type="text/css" scoped>
	.infobar{
		text-align: left;
		padding-left: 5px;
		margin-top: 5px;
	}
</style>